var FG;
if (!FG)
    FG = {};


// 本文件提供若干最基本的featureModelParser

FG.pitemFeatureModelParser = function(model) {
    // 解析PItem的Parser
    if (model.className !== 'ProjectItem') {
        return
    }
    var item_type = model.get('item_type');
    var itemUUID = model.get('uuid');
    var info = model.get('info');
    
    var featureType, widgetType, latlngs,
        featureOpts = {tag: itemUUID};
        widgetOpts = {};
    
    
    if (item_type === 'Point'){
        featureType = 'PointMarker';
        widgetType = 'DSV_PointWidget';
        latlngs = [info.lat, info.lon];
    } else if (item_type === 'Rect') {
        featureType = 'RectFeature';
        widgetType = 'DSV_RegionWidget';
        
        var pBase = FG.getPropertiesOfGroup('PItemRegion');
        featureOpts = (!!pBase && !!pBase.featureOpts) ? _.extend(pBase.featureOpts, featureOpts) : featureOpts;
    
        latlngs = [
            [info.lat1, info.lon1],
            [info.lat2, info.lon2]
        ];
    } else if (item_type === 'MultiLine') {
        featureType = 'LineFeature';
        widgetType = '';
    } else if (item_type === 'MultiPolygon') {
        featureType = 'PolygonFeature';
        widgetType = 'DSV_RegionWidget';
    
        var pBase = FG.getPropertiesOfGroup('PItemRegion');
        featureOpts = (!!pBase && !!pBase.featureOpts) ? _.extend(pBase.featureOpts, featureOpts) : featureOpts;
        
        if (!!model.mapData) {
            var geometry = model.mapData.get('geometry');
            latlngs = DX.geometryToLeafletLatLngs(geometry);
        }
    }

    var result = {
        featureType: featureType,
        widgetType: widgetType,
        latlngs: latlngs,
        featureOpts: featureOpts,
        widgetOpts: widgetOpts
    };
    
    return result;
};

FG.geojsonFeatureModelParser = function(obj) {
    if (!_.has(obj, 'type'))
        return;

    var result;
    if (obj.type === 'Feature') {
        var pBase = !!obj.propertyGroup ? FG.getPropertiesOfGroup(obj.propertyGroup) : {};
        var p = $.extend(true, pBase, obj.properties);
        result = {
            featureType: p.featureType,
            widgetType: p.widgetType,
            latlngs: DX.geometryToLeafletLatLngs(obj.geometry),
            featureOpts: _.extend({}, p.featureOpts),
            widgetOpts: _.extend({}, p.widgetOpts)
        };
        return result;
    }
};

FG.objFeatureModelParser = function(obj) {
    if (!_.has(obj, 'type')) {
        return
    }
    
    var result;
    if (obj.type === 'Rect') {
        var b = obj.bounds,
            pBase = !!obj.propertyGroup ? FG.getPropertiesOfGroup(obj.propertyGroup) : {};
            p = $.extend(true, {featureType: 'RectFeature'}, pBase, obj.properties);
        result = {
            featureType: p.featureType, 
            widgetType: p.widgetType,
            latlngs: [ [b.lat1, b.lon1], [b.lat2, b.lon2] ],
            featureOpts: _.extend({}, p.featureOpts),
            widgetOpts: _.extend({}, p.widgetOpts)
        };
        return result;
    }
};

FG.featureFeatureModelParser = function(feature) {
    
};